using System.Collections.Generic;
using UnityEngine;

public class GetPieceUI : MonoBehaviour
{
	public UIEventListener closebtn;

	public UISprite pieceflag;

	public Animator animator;
	//public Animation scaleanima;

	public Transform parenttra;

	public UIScrollView scroview;

	public UIScrollBar scrobar;

	public GameObject orgitem;

	public GotoItem tempgoto;

	private GameObject tempobj;

	public List<gotoinfo> levellist = new List<gotoinfo>();

	public List<gotoinfo> challengelist = new List<gotoinfo>();

	public List<GotoItem> havelist;

	private GameObject objui;

	private bool isshow;

	private void Start()
	{
		closebtn.onClick = OnClickcloseBtn;
	}

	public void enable(PieceData pd)
	{
		isshow = true;
		pieceflag.spriteName = "GY_SP_" + pd.id;
		levellist = MenuDataController.instance.Getpiecelevel(pd.id);
		challengelist = MenuDataController.instance.Getpiecechallenge(pd.id);
		gotoinfo item = default(gotoinfo);
		item.islock = false;
		item.curlv = -5;
		levellist.Add(item);
		for (int i = 0; i < challengelist.Count; i++)
		{
			levellist.Add(challengelist[i]);
		}
		for (int j = 0; j < levellist.Count; j++)
		{
			if (j >= havelist.Count)
			{
				tempobj = (UnityEngine.Object.Instantiate(orgitem) as GameObject);
				tempobj.transform.parent = parenttra;
				tempobj.transform.localPosition = new Vector3(0f, -40f * (float)j, 0f);
				tempobj.transform.localScale = new Vector3(1f, 1f, 1f);
				tempobj.name = "item" + j;
				tempgoto = tempobj.GetComponent<GotoItem>();
				tempgoto.enable(levellist[j]);
				havelist.Add(tempgoto);
			}
			else
			{
				havelist[j].enable(levellist[j]);
			}
		}
		int count = havelist.Count;
		if (havelist.Count > levellist.Count)
		{
			for (int k = levellist.Count; k < count; k++)
			{
				tempgoto = havelist[levellist.Count];
				havelist.RemoveAt(levellist.Count);
				UnityEngine.Object.Destroy(tempgoto.gameObject);
			}
		}
		if (objui == null)
		{
			objui = base.gameObject;
		}
		UnityVersionUtil.SetActiveRecursive(objui, state: true);
		animator.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
		scrobar.value = -1f;
		scroview.ResetPosition();
		Invoke("playanima", Time.deltaTime * 2f);
	}

	public void playanima()
	{
		/* scaleanima["PopWinAnimation"].time = 0f;
		scaleanima["PopWinAnimation"].speed = 1f;
		scaleanima.Play(); */
		animator.SetTrigger("popWin1");
	}

	public void OnClickcloseBtn(GameObject btn)
	{
		if (isshow)
		{
			isshow = false;
			MonoInstance<AudioController>.instance.play(AudioType.UI_BTN, 0f);
			/* scaleanima["PopWinAnimation"].time = scaleanima.clip.length;
			scaleanima["PopWinAnimation"].speed = -1f;
			scaleanima.Play(); */
			animator.SetTrigger("popWin2");
			Invoke("disable", animator.runtimeAnimatorController.animationClips[0].length);
		}
	}

	public void disable()
	{
		animator.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
		MenuBackController.instance.BackMenuUIstate();
		NGUITools.SetActive(objui, state: false);
	}
}
